package com.follow.controller;

import com.alibaba.fastjson.JSON;
import com.follow.common.PageUtil;
import com.follow.pojo.TbDepartment;
import com.follow.pojo.TbUserVO;
import com.follow.service.TbuserVOService;
import jdk.nashorn.internal.runtime.regexp.joni.exception.JOniException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2020/9/24.
 */
@Controller
public class TbUserVOController {

    @Autowired
    private TbuserVOService tbuserVOService;

    @RequestMapping(value = "selectUser",produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String selectUser(@RequestParam(value = "pageNum",defaultValue = "1",required = false) Integer pageNum,
                                                        Integer pageSize,Integer id,String userId,String userName,String password,
                                                        Integer roleId,Integer sex,String phone,String mail,Integer departmentId){
        PageUtil<TbUserVO> pageUtil = tbuserVOService.selectUserVO(pageNum,pageSize,id,userId,userName,password,roleId,sex,phone,mail,departmentId);
        return JSON.toJSONString(pageUtil);
    }
    @RequestMapping(value = "department" ,produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String selectDepartment(){
        List<TbDepartment> tbDepartments = tbuserVOService.selectDepartment();
        return JSON.toJSONString(tbDepartments);
    }

    @RequestMapping(value = "addDoctor",produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String addDoctor(String userId, String userName, Integer sex, Integer age, @DateTimeFormat(pattern ="yyyy-MM-dd")Date birthday, String phone, String mail, String password, Integer roleId, Integer departmentId){
        boolean b = tbuserVOService.addDoctor(userId,userName,sex, age,birthday,phone,mail,password,roleId,departmentId);
        return JSON.toJSONString(b);
    }
    @RequestMapping(value = "selectOne" ,produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String selectOne(Integer id){
        TbUserVO findOne = tbuserVOService.selectOne(id);
        return JSON.toJSONString(findOne);
    }

    @RequestMapping(value = "updateOne" ,produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String updateOne(TbUserVO tbUserVO){
        boolean b =tbuserVOService.updateOne(tbUserVO);
        return JSON.toJSONString(b);
    }
    @RequestMapping(value = "deleteBeach" ,produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String removeBeach(@RequestParam("ids[]") String[] ids){
        boolean b =tbuserVOService.removeBeach(ids);
        return JSON.toJSONString(b);
    }
}
